package com.custom.lessonstudy.di;

import com.custom.lessonstudy.net.BaseHttpResponse;
import com.custom.lessonstudy.ui.bean.SmsBean;
import com.google.gson.Gson;

import java.util.HashMap;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

/**
 * @author by cyb on 2019/1/3.
 */

public class SuManHttpService {
    /**
     * ApiService Api接口每一个接口
     */
    ApiService apiService;

    public SuManHttpService() {
        if (apiService==null){
            retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
            //获取接口对象
            apiService = retrofit.create(ApiService.class);
        }
    }

    /**
     * 类转化请求体
     *
     * @param requestBean 所有请求参数封装的类
     * @return Okhttp需要的请求体
     */
    public static String creatRequestBody(BaseRequestBean requestBean) {
        // final String params = new Gson().toJson(requestBean);
        String jsonstr = new Gson().toJson(requestBean).replace("\\", "");
        // String json = "{\"param\":" + jsonstr + "}";
        //RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonstr);
        return jsonstr;
    }




    /**
     * 刷新客户端连接时间接口
     */
    public Observable<ResponseBody> login() {
        return apiService.login();
    }

    /**
     * 发送短信
     *
     * @param map
     */
    public Observable<BaseHttpResponse<SmsBean>> sendMsg(HashMap map) {
        return apiService.sendMsg(map);
    }

}



